import tkinter as tk
import op
import find_card
import spilt_char
import predict


def go():
    path = t1.get("1.0", "end")
    path = path[:len(path) - 1]
    print(path)
    start(path)


def start(path):
    print("识别中...")
    name = find_card.find_card(path)
    print("完成find_card")
    spilt_char.spilt_char(name)
    print("完成spilt_card")
    ans = predict.predict("Image/car_char/" + name + "/")
    print("识别完毕！")
    t2.insert("insert", ans)


if __name__ == "__main__":
    window = tk.Tk()
    window.title("车牌识别系统")
    window.geometry('200x200')
    p = tk.Label(window, text='车牌识别系统', font=('Arial', 12), width=15, height=2)
    p.grid(row=0, column=0)
    frame1 = tk.Frame(window)
    frame1.grid(row=1, column=0, sticky='w')
    r = tk.Label(frame1, text='path:', font=('Arial', 12), width=5, height=2)
    r.pack(side='left')
    t1 = tk.Text(frame1, width=20, height=2)
    t1.pack(side='left')
    b = tk.Button(window, text='开始识别', height=2, command=go)
    b.grid(row=2, column=0)
    frame3 = tk.Frame(window)
    frame3.grid(row=3, column=0, sticky='w')
    k = tk.Label(frame3, text='output:', font=('Arial', 12), width=5, height=2)
    k.pack(side='left')
    t2 = tk.Text(frame3, width=20, height=2)
    t2.pack(side='left')
    l = tk.Label(window, text='author : pipibao')
    l.grid(row=4, column=0)
    window.mainloop()
